export class EventRouter {
	#api = {}
	routes: any[]
	constructor() {
		this.routes = new Array()
	}
	// 添加api
	addApi(key: string, api: any) {
		this.#api[key] = api
	}
	// 添加多个路由
	addRoutes(routes) {
		this.routes = routes
	}
	// 触发指定名称的路由回调
	router({ name, data }) {
		// 找到与传入名称一致的事件对象
		const findRoute = this.routes.find(item => item.name === name)
		// 传参并执行对应事件对象的回调
		findRoute && findRoute.callback(this.#api, data)
	}
}